Xbasic

FORMAT_DATA Function

Syntax

Result_String as C = FORMAT_DATA( Input_Value as C, Format_Code as C)

Result_String as C = FORMAT_DATA( Input_Value as D, Format_Code as C )

Result_String as C = FORMAT_DATA( Input_Value as L, Format_Code as C )

Result_String as C = FORMAT_DATA( Input_Value as N, Format_Code as C [, Field_Width as N [, Field_Decimal as N ]] )

Arguments

input_valueCharacter Date Logical Numeric

The value to format.

format_codeCharacter

A format string. Refer to Display Formats.

fld_widthNumeric

Default = 20. The maximum expected length of the formatted string. Value must be larger than the length of the formatted string. For numeric values only.

fld_decNumeric

Default = 2. The number of characters after the decimal point. Output will be padded with zeros. For numeric values only.

Description

Formats an input string using a format_code. Returns a character string.

Discussion

The FORMAT_DATA() function formats a character, date, numeric, or logical value. For numeric inputs, FORMAT_DATA() is the same as calling ALLTRIM(STR(...)).

? format_data("edwaRd","Z")
= "Edward"

? format_data(date(),"3C")
= "16 MARCH 2017"

? format_data(.t.,"2")
= "Yes"

? format_data(1234567.89,",B*")
= "********1,234,567.89"

dim nn as N
nn = 12345678900000.456
? format_data(nn,"$",22)
= "$12,345,678,900,000.46"

See Also